#include "glModel.h"



using namespace  std;


glModel::glModel(void)
{
	this->ModelInfo= nullptr;
	this->ModelData= nullptr;

}

glModel::~glModel(void)
{
}


void glModel::RenderingModel(void)
{

			GLubyte testcolor[4];
			testcolor[0]=255;
			testcolor[1]=255;
			testcolor[2]=0;
			testcolor[3]=10;

	//glColor3ub(0,127,127);
			glColor4ubv(testcolor);
	for(int i=0;i<this->ModelInfo->numFaces;i++){
		glBegin(GL_LINE_STRIP);
			for(int j=0;j<this->ModelData->ModelMesh[i].numVerticesEachFace;j++){	

				glVertex3d(this->ModelData->ModelVertices[(this->ModelData->ModelMesh[i].VerticesIndex[j])].x,
					       this->ModelData->ModelVertices[(this->ModelData->ModelMesh[i].VerticesIndex[j])].y,
					       this->ModelData->ModelVertices[(this->ModelData->ModelMesh[i].VerticesIndex[j])].z );
			}//end for			
		glEnd();
	}
}


void glModel::SaveModel(char* filename)
{
	ofstream fileStream;
	fileStream.open(filename,ios::binary) ;

		fileStream<<"test binary";
	
	fileStream.close();

}


glTriModel* glModel::Copy2TriModel(void)
{

	if(this->ModelInfo->maxVerticesAllFaces!=3)
		return nullptr;

	glTriModel *tmp;
	tmp= new glTriModel();

	tmp->Header.numVertex=this->ModelInfo->numVertices;
	tmp->Header.numTriMesh=this->ModelInfo->numFaces;

	tmp->Vertex = new _ModelVertex[tmp->Header.numVertex];

	for(int i=0;i<tmp->Header.numVertex;i++){
		tmp->Vertex[i].x=this->ModelData->ModelVertices[i].x;
		tmp->Vertex[i].y=this->ModelData->ModelVertices[i].y;
		tmp->Vertex[i].z=this->ModelData->ModelVertices[i].z;
	}


	tmp->TriMesh = new _ModelTriMesh[tmp->Header.numTriMesh];

	for(int i=0;i<tmp->Header.numTriMesh;i++){
		tmp->TriMesh[i].Index[0]=this->ModelData->ModelMesh[i].VerticesIndex[0];
		tmp->TriMesh[i].Index[1]=this->ModelData->ModelMesh[i].VerticesIndex[1];
		tmp->TriMesh[i].Index[2]=this->ModelData->ModelMesh[i].VerticesIndex[2];
	}




	return tmp;
	//return glTriMode();
}


bool glModel::isTriMesh(void)
{
	if(this->ModelInfo->maxVerticesAllFaces==3){
		return true;
	}else{
		return false;
	}

}
